<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('仓库列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>仓库名称：</label>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <label>仓库地址：</label>
                            <input type="text" name="address"/>
                        </li>
                        <li>
                            <label>负责人：</label>
                            <input type="text" name="principalName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>

                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "business/factory";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "仓库",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'name',
                    title: '仓库名称'
                },
                {
                    field: 'address',
                    title: '仓库地址'
                },
                {
                    field: 'totalCapacity',
                    title: '总容量'
                },
                {
                    field: 'usedCapacity',
                    title: '已使用容量'
                },
                {
                    field: 'flag',
                    title: '使用率',
                    formatter: function (value, row, index) {
                        var flag = ((parseFloat(row.usedCapacity) / parseFloat(row.totalCapacity)).toFixed(4) * 100);
                        return '<span class="badge badge-info">' + flag + '\%' + '</span>'
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'principalName',
                    title: '负责人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="getStock(\'' + row.id + '\')"><i class="fa fa-search"></i>查看库存</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="selectFactory(\'' + row.id + '\')"><i class="fa fa-edit"></i>选择</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /** 查看仓库库存 */
    function getStock(id) {
        $.modal.open("查看仓库库存", ctx + "/business/stock/getStock/" + id, 1200);
    }

    function selectFactory(id) {
        parent.setFactory(id);
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);//关闭当前页
    }
</script>
</body>
</html>